


from rest_framework import serializers
from django.contrib.auth.models import Permission,ContentType


class PermModelSerializer(serializers.ModelSerializer):
    # content_type = serializers.StringRelatedField() # 只作用于序列化

    # queryset作用于当前外键管理字段对象，在反序列化的时候根据前端传的id过滤出具体对象
    # content_type = serializers.PrimaryKeyRelatedField(
    #     queryset=ContentType.objects.all()
    # )

    class Meta:
        model = Permission
        fields = [
            'id',
            'name',
            'codename',
            'content_type'
        ]


class PermContentTypeModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = ['id', 'name']
